﻿#region License

// PentaBiz - Sustainable Software Development Framework Copyright (C) 2013 Zoltán Csizmazia
// 
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PentaBiz.Cloud.Services;

namespace Cloud.Services.Hosting.ConsoleHost
{
    internal class Program
    {
        private const string GplWarning = @"
****************************************************************************
* PentaBiz  Copyright (C) 2013  PentaTrade and Zoltán Csizmazia
****************************************************************************
* This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
* This is free software, and you are welcome to redistribute it
* under certain conditions; type `show c' for details. 
****************************************************************************
";

        private static void Main(string[] args)
        {
            Console.Title = "PentaBiz - Initializing...";
            Console.WriteLine(GplWarning);

            //Generic service manager maintains the wcf services...
            using (var s = new GenericServiceHostManager())
            {
                Console.Title = "PentaBiz - Starting...";
                s.Start();
                Console.Title = "PentaBiz - Started!";

                ConsoleKey key = ConsoleKey.F1;
                do
                {
                    switch (key)
                    {
                        case ConsoleKey.F1:
                            Console.WriteLine("Press O to open services in browser");
                            break;
                        case ConsoleKey.O:
                            s.CloudServiceHosts.ToList().ForEach(a =>
                                {
                                    Process.Start(a.Address.ToString());
                                    Thread.Sleep(TimeSpan.FromSeconds(3));
                                });

                            break;
                    }

                    Console.WriteLine("Press ESC to exit");
                } while ((key = Console.ReadKey().Key) != ConsoleKey.Escape);

                Console.Title = "PentaBiz - Stopping...";
                s.Stop();
            }

            Console.Title = "PentaBiz - Stopped!";
        }
    }
}